<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
function getAllMatches($tournamentId) {
  $getAllMatchsSql = 'SELECT * FROM tournamentMatch NATURAL LEFT JOIN tournamentField NATURAL LEFT JOIN'.
      ' tournamentPlayer NATURAL LEFT JOIN tournamentRoundType WHERE idTournamentDraw = '.
      $tournamentId .' GROUP BY  (idTournamentMatch)' ;
  return mysql_query($getAllMatchsSql);
}

function getAllPlayerFromTournament($tournamentId) {
  $getAllPlayerFromTournamentSql = 'SELECT DISTINCT idPlayer, playerSurname,
      playerLastname FROM tournamentMatch, tournamentPlayer
      WHERE (idPlayer1 = idPlayer
      OR idPlayer = idPlayer2
      OR idPlayer3 = idPlayer
      OR idPlayer4 = idPlayer )
      AND idTournamentDraw = '. $tournamentId . ' ORDER BY playerSurname, playerLastname';
  return mysql_query($getAllPlayerFromTournamentSql);
}

function getAllScoresFromTournament($tournamentId) {
  $getAllPlayerFromTournamentSql = 'SELECT * FROM tournamentGameScore
      NATURAL JOIN tournamentMatch
      WHERE idTournamentDraw = '. $tournamentId;
  return mysql_query($getAllPlayerFromTournamentSql);
}




$allMatches = getAllMatches($tournamentId);
$MatchesCount = mysql_num_rows($allMatches);
$numberOfRound = getNumberOfRound($tournamentId);

?>
<?php include($ROOT . "controlleur/json.php");
  $json = new Services_JSON();?>
<script type="text/javascript">
  var numberOfRound = <?php echo $numberOfRound ?>;
  var idTournamentDraw = <?php echo $tournamentId ?>;
  var allMatches = <?php echo $json->encode(mysqlQueryToArray($allMatches)) ?>;
  var allPlayersFromJson = <?php echo $json->encode(mysqlQueryToArray(getAllPlayerFromTournament($tournamentId))) ?>;
  var allScoresFromJson = <?php echo $json->encode(mysqlQueryToArray(getAllScoresFromTournament($tournamentId))) ?>;
  var tournamentName = '<?php echo getTournamentName($tournamentId) ?>';
  var tournamentDrawTypeName = '<?php echo getTournamentDrawTypeName($tournamentId) ?>';
  var allTournamentDraws = <?php echo $json->encode(mysqlQueryToArray(getAllTournamentDraws($tournamentId))) ?>;

  
</script>